<?php $this->load->view('header');?>

<body class="childrenBody">
    <blockquote class="layui-elem-quote news_search">
		<form class="layui-form" action="" style="display: inline;">
			<div class="layui-inline">
			    <div class="layui-input-inline">
			    	<input type="text" name="keyword" value="" placeholder="搜姓名、手机号码" class="layui-input search_input">
			    </div>
			    <a class="layui-btn layui-btn-normal Sear_btn"><i class="layui-icon">&#xe615;</i>查询</a>
			</div>
		</form>
		<div style="float: right;">
			<div class="layui-inline">
				<a class="layui-btn layui-btn-custom userAdd_btn"><i class="layui-icon">&#xe654;</i> 会员签到</a>
			</div>
		</div>
		
	</blockquote>

	<!-- 视图 -->
	<div class="layui-form news_list">
		<form class="layui-form">
			<table class="layui-table" lay-even="" lay-skin="line">
			    <thead>
				<tr>
					<th>会员名</th>
					<th>联系电话</th>
					<th>课程</th>
					<th>卡名称</th>
					<th>上课时间</th>
					<th>费用</th>
					<th>场馆</th>
					<th>教练</th>
					<th>操作</th>
				</tr> 
			    </thead>
				<tbody class="goods_content" id="view"></tbody>
				
			</table>
			<div class="page_box" style="float: right;padding-right: 10px;">
				<div id="listpage"></div>
			</div>
		</form>
	</div>

	<!-- 模板 -->
	<script id="demo" type="text/html">
	    {{#  layui.each(d.list, function(index, item){ }}
			<tr>
			  <td width='150'>
			  	{{#  if(item.headimg){ }}
			  	<img src="{{item.headimg}}" style="width: 30px;border-radius: 100%;height: 30px;">
			  	{{# }else{ }}
				<img src="plugins/layui/images/user_img.png" style="width: 30px;border-radius: 100%;">
			  	{{#  } }}&nbsp;&nbsp;{{ item.nickname }}
			  </td>
			  <td>{{ item.mobile }}</td>
			  <td>{{ item.course_name }}</td>
			  <td>{{ item.card_name }}</td>
			  <td>{{ item.sdate }} {{ item.stime }}</td>
			  <td>{{ item.price }}</td>
			  <td>{{ item.shop_name }}</td>
			  <td>{{ item.coach_name }}</td>
			  <td>
			    <a class="layui-btn layui-btn-primary layui-btn-mini" id="cancel{{ item.id }}" title="取消签到">
			      <i class="layui-icon">&#xe64f;</i>
			    </a>
			  </td>
			</tr>
	    {{#  }); }}

	    {{#  if(d.list.length === 0){ }}
	      暂无数据
	    {{#  } }} 
	</script>

	<script type="text/javascript">
	layui.config({
		version: true
	}).use(['jquery','layer', 'laytpl', 'form', 'element', 'laypage'],function(){
		var layer = parent.layer === undefined ? layui.layer : parent.layer,
			laytpl = layui.laytpl,
			form = layui.form,
			element = layui.element,
			laypage = layui.laypage,
			$ = layui.jquery;

			load_list();

			//查询
			$('.Sear_btn').click(function() {
				var keyword = $("input[name='keyword']").val();

				load_list('',keyword);
			});

			//添加
			$('.userAdd_btn').click(function(event) 
			{
		        var index = layui.layer.open({
					title : "添加签到",
					type : 2,
					content : "admin.php/Report/add_appoint",
					cancel: function(index, layero){ 
							location.reload();						 
					}  
				})

				//改变窗口大小时，重置弹窗的高度，防止超出可视区域
				$(window).resize(function(){
					layui.layer.full(index);
				})
				layui.layer.full(index);
			});

			function load_list(p,k)
			{
				$.get('admin.php/Report/get_list',{page:p,keyword:k}, function(data) 
				{
					var getTpl = demo.innerHTML;
					laytpl(getTpl).render(data, function(html){
					  $('#view').html(html);
					});

					layui.each(data.list, function(index, el) 
					{
						//分页
						laypage.render({
						  elem: 'listpage'
						  ,count: data.count //数据总数，从服务端得到
						  ,theme: '#1E9FFF'
						  ,limit: 10
						  ,curr:p
						  ,jump: function(obj, first){
						    //首次不执行
						    if(!first){
						      load_list(obj.curr,k);
						    }
						  }
						});

						
						//取消签到
						$('#cancel'+el.id).click(function() 
						{
							layer.confirm('是否取消签到',{icon:3, title:'提示信息'},function(index){
								$.get('admin.php/Report/cancel_appoint',{id:el.id}, function(res) {
									if (res.status == 200) {
										layer.msg(res.message, {icon:1});
										location.reload();
									}
									else
									{
										layer.msg(res.message, {icon:2});
									}
								},"json");
							});
						});


						form.render(); //更新全部
					});
				},'json');

			}

	});
	</script>

</body>
</html>